package com.dlyk.service.impl;

import com.dlyk.constant.Constants;
import com.dlyk.mapper.PermissionMapper;
import com.dlyk.model.Permission;
import com.dlyk.model.Role;
import com.dlyk.service.PermissionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionServiceImpl implements PermissionService {

    @Resource
    private PermissionMapper permissionMapper;

    /**
     * 根据角色id查询权限列表（分页查询）
     */
    @Override
    public PageInfo<Permission> getPermissionListByRoleId(Integer roleId, Integer current) {

        // 1、设置PageHelper
        PageHelper.startPage(current, Constants.PAGE_SIZE);

        // 2、查询
        List<Permission> permissionList = permissionMapper.selectPermissionListByRoleId(roleId);

        // 3、封装分页数据到PageInfo
        PageInfo<Permission> permissionPageInfo = new PageInfo<>(permissionList);

        return permissionPageInfo;
    }

    /**
     * 根据角色id查询未拥有的权限列表
     */
    @Override
    public List<Permission> getNotOwnedPermissionList(Integer roleId) {
        return permissionMapper.selectNotOwnedPermissionList(roleId);
    }

}

